/**
 * 部门用能=>用能概况=>搜索组件
 *
 */
import * as React from "react";
import { Button } from "antd";
import IconFont from "../../../../../../assets/ICON";

export interface SearchBarProps {
  onChange?: (num: number) => any;
  defaultValue?: number;
  value?: number;
}

export interface SearchBarState {
  type: number;
}

class SearchBar extends React.Component<SearchBarProps, SearchBarState> {
  state = { type: 1 };
  render() {
    let { type } = this.state;
    let onChange = this.props.onChange;
    return (
      <>
        <div className="rowcon_body">
          <div className="changeType_btn f-left">
            <Button
              className="left"
              type={type === 1 ? "primary" : "default"}
              icon={<IconFont type="icon_dian" />}
              onClick={() => {
                this.setState({ type: 1 });
                if (onChange) {
                  onChange(1);
                }
              }}
            >
              电
            </Button>
            <Button
              className="right"
              type={type === 2 ? "primary" : "default"}
              icon={<IconFont type="icon_shui" />}
              onClick={() => {
                this.setState({ type: 2 });
                if (onChange) {
                  onChange(2);
                }
              }}
            >
              水
            </Button>
          </div>

          <div className="clear"></div>
        </div>
      </>
    );
  }
  componentDidMount() {
    let value =
      typeof this.props.value === "undefined"
        ? this.props.defaultValue
        : this.props.value;
    this.setState({
      type: value ? value : 1,
    });
  }
}

export default SearchBar;
